/*
Flexperimentos.
Copyright (C) 2007  Richard R Manzke

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/
package br.absolutobrasil.formatters
{
	import mx.formatters.Formatter;

	public class CPFFormatter extends Formatter
	{
		include "../core/Versao.as";	
		 /**
      * CPFFormatter
         * @author Richard R Manzke <tuco.net@gmail.com>
         * @langversion ActionScript 3.0
         */
		private const CPF_LENGTH:int = 11;
		
		public function CPFFormatter()
		{
			super();
		}
		override public function format(value:Object):String{
                   // retorna Vazio se não existe valor de entrada.
                        if (!value)
                             return "";
                              
                        var strValue:String = value.toString();
                 // Retorna Vazio se o valor de entrada com tamanho incorreto.
                   if (strValue.length != CPF_LENGTH) 
                             return "";
                              
                        // Retorna a entrada formatada.
                 return strValue.substr(0,3) + "." + 
                                    strValue.substr(3,3) + "." +
                                    strValue.substr(6,3) + "-" +
                                    strValue.substr(9,2);
           }
		
	}
}